"""
往hero表中添加数据
"""
from pymysql import Connection

conn = None
cursor = None
try:
    conn = Connection(
        host="localhost",
        port=3306,
        user = "root",
        password = "root",
        database="db03",
        charset="utf8",
        autocommit=True # 设置自动提交
    )
    cursor = conn.cursor()
    sql = "INSERT INTO hero VALUES(null,'鲁智深',30,'男','山西五台')"
    cursor.execute(sql)

    # conn.commit()
    print("数据添加完成")
except Exception as e:
    print("异常",e)
finally:
    if cursor:
        cursor.close()
    if conn:
        conn.close()